package com.huikeportal.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.huikeportal.model.SiteAllInfo;
import com.huikeportal.model.TodayIndexes;
import com.huikeportal.model.UserInfo;
import com.huikeportal.model.common.PageDataVo;
import com.huikeportal.service.FootfallGlobalService;
import com.huikeportal.service.LoginService;
import com.huikeportal.service.TodayIndexesService;

@Controller
@Scope("prototype")
public class TotleTrafficController {
	@Autowired
	private HttpSession session;

	@Autowired
	private LoginService loginService;
	
	@Autowired
	private TodayIndexesService todayIndexesService;
	
	@Autowired
	private FootfallGlobalService footfallGlobalService;
	@RequestMapping("/totalTraffic")
	public String totalTraffic(ModelMap model,String siteId) throws Exception {
		UserInfo userInfo = (UserInfo) session.getAttribute("sessionUserName");
		userInfo=loginService.getUserInfo(userInfo);
		String siteType="300";//场所类型是300
		
		 List<String> userIndexList = footfallGlobalService.getUserIndex(userInfo);
        List<String> siteTypes = new ArrayList<String>();
        siteTypes.add(FootfallConstant.WHOLE_SITETYPE);
		//我的数据_实时指标 model为1_1
        String moduleId1 = FootfallConstant.MYFOOTFALL_CUR;
        //获取实时指标
        List<String> indexListCurrent = footfallGlobalService.getIndexListOfModel(userIndexList, moduleId1, siteTypes);
        model.addAttribute("indexListCurrent ",indexListCurrent);
        
		SiteAllInfo siteAllInfo=footfallGlobalService.selectSiteByUserId(userInfo,siteType);
		if(siteId!=null&&siteId!=""){
			siteAllInfo.setSiteid(siteId);
		}
		String siteName=todayIndexesService.getSiteNameBySiteId(siteAllInfo.getSiteid());
		model.addAttribute("siteName", siteName);
		model.addAttribute("datetime", todayIndexesService.getDate());
		HashMap<String, Object> todayIndexes= todayIndexesService.getTodayIndexes(siteId,indexListCurrent);
		model.addAttribute("todayIndexes",todayIndexes);
		String menuHtml = loginService.getMenuHtml(userInfo, "totalTraffic");
		model.addAttribute("menuHtml", menuHtml);// 左侧菜单html
		return "totalTraffic";
	}
}
